#!/usr/bin/perl

require "./mailadmin-lib.pl";
my ($k, $i, %st_serv, $wb_port);


unless (&qmail_dir_check())
{
    &redirect('maildir_edit.cgi');
}

&header($text{'index_title'}, "", "index", 0, 1);


&get_service_status(\%st_serv);
$wb_port = &get_wbmail_port();

print "<form name=servform action=index.cgi method=post onsubmit='return do_submit();'>\n";
#table total virturl domain
print "<table class=mode1 width=100%>\n";

print "<tr><td valign=top width=90%>\n";

#list table of virturl domain
print "<table class=mode1 celladding=0 cellspacing=0 width=100%>\n";
print "<tr class=title1><td><b>$text{'servname'}</b></td><td width=80><b>$text{'status'}</b></td><td><b>$text{'descrip'}</b></td></tr>\n";

print "<tr class=mode1><td><input type=radio name=servradio value='mailserv'>$text{'mailserv'}</td><td>$st_serv{'mailserv'}</td><td>$text{'des_mail'}</td></tr>\n";
print "<tr class=mode2><td><input type=radio name=servradio value='smtpserv'>$text{'smtpserv'}</td><td>$st_serv{'smtpserv'}</td><td>$text{'des_smtp'}</td></tr>\n";
print "<tr class=mode1><td><input type=radio name=servradio value='popserv'>$text{'popserv'}</td><td>$st_serv{'popserv'}</td><td>$text{'des_pop'}</td></tr>\n";
printf "<tr class=mode2><td><input type=radio name=servradio value='webmailserv'>$text{'webmailserv'}</td><td>$st_serv{'webmailserv'}</td><td>%s</td></tr>\n", &text('des_webmail', $wb_port);

print "</table>\n";

print "</td><td valign=top>\n";

print "<table>";
print "<tr><td><input class=button type=submit name=serv_start value=\"$text{'btn_start'}\" onclick='return onsubmit_servact(this)'></td></tr>\n";
print "<tr><td><input class=button type=submit name=serv_stop value=\"$text{'btn_stop'}\" onclick='return onsubmit_servact(this)'></td></tr>\n";
print "<tr><td><input class=button type=submit name=serv_restart value=\"$text{'btn_restart'}\" onclick='return onsubmit_servact(this)'></td></tr>\n";
print "<tr><td><input class=button type=submit name=serv_config value=\"$text{'btn_config'}\" onclick='return onsubmit_conf()'></td></tr>\n";
print "</table>";
print "</td></tr>\n";

print "</table>";

print "<table class=mode1>";

print "<tr><td>$text{'vdom_usr_admin'}&nbsp;&nbsp;&nbsp;<td><input class=button1 type=submit name=vdom_config value=\"$text{'btn_config'}\" onclick='onsubmit_vdom_config()'></tr>";
print "<tr><td>$text{'mailbox_dir'}&nbsp;&nbsp;&nbsp;<td><input class=button1 type=submit name=setdir_load value=\"$text{'btn_load'}\" onclick='onsubmit_mbdir_config()'></tr>";

print "</table>";


print "<input type=hidden name=serv_act value=''>\n";

print "</form>\n";



print <<EOF;
<script>
function do_submit()
{
    document.forms[0].serv_start.disabled = true;
    document.forms[0].serv_stop.disabled = true;
    document.forms[0].serv_restart.disabled = true;
    document.forms[0].serv_config.disabled = true;
    document.forms[0].vdom_config.disabled = true;
    document.forms[0].setdir_load.disabled = true;
}

function onsubmit_servact(obj)
{

    var i;
    var found = false;
    
    for(i = 0; i < document.servform.servradio.length; i++)
    {
	if (document.servform.servradio[i].checked)
	{
	    found = true;
	    break;
	}
    }

    if (!found)
    {
	alert("$text{'msg_not_select_service'}");
	return false;
    }

    document.servform.action = "serv_act.cgi";
    if (obj == document.servform.serv_start)
    {
	document.servform.serv_act.value = "start";
    }
    else if (obj == document.servform.serv_stop)
    {
	document.servform.serv_act.value = "stop";
    }
    else if (obj == document.servform.serv_restart)
    {
	document.servform.serv_act.value = "restart";
    }
}

function onsubmit_vdom_config()
{
    document.servform.action = "list_domain.cgi";
}

function onsubmit_mbdir_config()
{
    document.servform.action = "maildir_edit.cgi";
}

function onsubmit_conf()
{
    var i;
    var found = false;
    
    for(i = 0; i < document.servform.servradio.length; i++)
    {
	if (document.servform.servradio[i].checked)
	{
	    found = true;
	    break;
	}
    }

    if (!found)
    {
	alert("$text{'msg_not_select_service'}");
	return false;
    }

    document.servform.action = "serv_conf.cgi";
}

</script>
EOF


&footer("/", $text{"index"});
